import * as THREE from 'three'
import Sizes from './Sizes';
import Camera from './Camera'
import Renderer from './Renderer';
import Time from './Time';
import Cube from './Cube';
import Particles from './Particles';
import Light from './Light';
import Scroll from './Scroll';
import Cursor from './Cursor';
// 特别说明 窗口尺寸改变的时候Webgl元素的长宽不会变化
// 渲染的尺寸应该根据outBox 这个元素的长宽而变化
export default class Manager {
    static instance;

    constructor(canvas) {
        if (Manager.instance) return Manager.instance
        Manager.instance = this;
        this.canvas = canvas;
        // this.outBox = outBox;

        this.scene = new THREE.Scene();
        this.sizes = new Sizes();
        this.camera = new Camera();
        this.Light = new Light();
        this.time = new Time();
        this.renderer = new Renderer();

        this.cube = new Cube();
        this.particles = new Particles();

        this.cursor = new Cursor();
        this.scroll = new Scroll();

        this.time.on(Time.UPDATE_EVENT, () => {
            this.update();
        })
        this.sizes.on(Sizes.RESIZE_EVENT, () => {
            this.resize();
        })
    }
    update() {
        this.camera.update();
        this.renderer.update();
        this.cube.update();
        this.cursor.update();
    }
    resize() {
        this.camera.resize();
        this.renderer.resize();
    }

    destroy() {
        Manager.instance = null;
    }
}